package org.iabako.shared.iservice.business;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import org.iabako.shared.entity.business.Installment;
import org.iabako.shared.entity.business.Payment;
import org.iabako.shared.entity.business.Sale;
import org.iabako.shared.entity.business.SaleProductService;
import org.iabako.shared.iservice.generic.BusinessEntityServiceAsync;
import org.iabako.shared.iservice.generic.CRUDServiceAsync;
import org.iabako.shared.iservice.generic.SearchServiceAsync;

import java.util.List;

/**
 * Created by jose on 26/08/14.
 */
public interface SaleServiceAsync extends SearchServiceAsync, CRUDServiceAsync, BusinessEntityServiceAsync {

    void save(boolean isDraft, Sale sale, List<SaleProductService> productsServices, List<Payment> payments, List<Installment> installments, AsyncCallback<Sale> asyncCallback);

    void save(Sale sale, AsyncCallback<Sale> async);

    void getPayments(Sale sale, AsyncCallback<List<Payment>> async);

    void getInstallments(Sale sale, AsyncCallback<List<Installment>> async);

    void paymentToInstallment(Long idPayment, AsyncCallback<Void> async);

    void installmentToPayment(Installment installment, AsyncCallback<Void> asyncCallback);

    void calculateStatusAndSave(Sale sale, boolean isDraft, AsyncCallback<Sale> async);

    void getCustomInstallmentsDefinition(Sale sale, AsyncCallback<List<Installment>> async);

    void getProductServiceList(Sale sale, AsyncCallback<List<SaleProductService>> async);

    void stopUndefinedInstallmentsCreation(Sale sale, AsyncCallback<Sale> async);

    void rawSave(Sale sale, AsyncCallback<Sale> async);

    void addProductsServicesToSale(boolean isDraft, Sale saleFromDB, List<SaleProductService> productsServices, AsyncCallback<Void> async);

    public static final class Util {
        private static SaleServiceAsync instance;

        public static final SaleServiceAsync getInstance() {
            if (instance == null) {
                instance = GWT.create(SaleService.class);
            }
            return instance;
        }
    }
}
